﻿
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
namespace taskmgr
{
	/// <summary>
	/// Description of frmdll.
	/// </summary>
	public partial class frmdll : Form
	{
		public int ProcID;
		public frmdll()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			
		}
		void GetModulesEx(){
			Process p=Process.GetProcessById(ProcID);
			ProcessModuleCollection mod=p.Modules;
			foreach(ProcessModule pm in mod){
				ListViewItem lv=new ListViewItem();
				lv.Text=pm.FileName;
				int ms=pm.ModuleMemorySize;
				lv.SubItems.Add(string.Format("{0:0,0}",ms/1024));
				listView1.Items.Add(lv);
				pm.Dispose();
			}
			this.Text="load modules count:"+listView1.Items.Count.ToString();
			
		
		}
		void FrmdllLoad(object sender, EventArgs e)
		{
			int fw=this.Width;
			listView1.Columns.Add("path",Convert.ToInt32(fw*0.8),HorizontalAlignment.Left);
			listView1.Columns.Add("memory size",Convert.ToInt32(fw*0.2),HorizontalAlignment.Left);
			
			GetModulesEx();
		}
		
		void FrmdllFormClosed(object sender, FormClosedEventArgs e)
		{
			
		}
		
		void ListView1Click(object sender, EventArgs e)
		{
			ListViewItem lv=listView1.SelectedItems[0];
			string fp=lv.Text;
			string info="";
			if(File.Exists(fp)){
				string company=SystemInfo.GetFileInfo(fp,1);
				string ver=SystemInfo.GetFileInfo(fp,2);
				string dest=SystemInfo.GetFileInfo(fp,4);
				info=string.Format("公司:{0}  版本:{1}  描述:{2}",company,ver,dest);
				Debug.Print(info);
				spanel1.Text=info;
			}
		}
		
		void ListView1DoubleClick(object sender, EventArgs e)
		{
			ListViewItem lv=listView1.SelectedItems[0];
			string fp=lv.Text;
			if(File.Exists(fp)){
				SystemInfo.ShowPropertyFile(fp,this.Handle);
			}
		}
	}
}
